## For dir
WORK="${HOME}/work"

# CD
function cd() {
    builtin cd -- "$@" && { [ "$PS1" = "" ] || ls -htpF --color=auto; };
}

# cat，if installed bat use it
[[ -e `which bat` ]] && alias cat=`which bat`

# dotfiles
alias tod="cd ${HOME}/work/dotfiles"
alias tow="cd ${HOME}/work"

# Download
DL=${HOME}/Downloads
alias dl="cd ${DL}"
alias dlf="cd ${DL}/firefox"
alias dlc="cd ${DL}/chrome"
alias dlo="cd ${DL}/other"
# Codes
CDS=${WORK}/codes
alias ccode="cd ${CDS}"
alias cgo="cd ${CDS}/go"
alias ccc="cd ${CDS}/c"
alias ccr="cd ${CDS}/rust"
alias cccp="cd ${CDS}/cpp"
alias tmp="cd /tmp"

# screensave
alias spng="cd ${WORK}/person/pictures/screensave"
alias rspng="ranger ${WORK}/person/pictures/screensave"

## For vi
## fix in tmux
#[ ${TMUX} ] && [ ${TERM} != "linux" ] && alias vim="TERM=xterm-256color vim"
alias v="vim"
alias editor="vim"
alias sv="sudo vim"
alias svi="sv"
alias svim="sv"
# TO vim rc dir
alias tov="cd ${HOME}/.vim"
alias vc="vim ${HOME}/.vim"
alias vvc="vim ${HOME}/.vim/vimrc"
alias vvp="vim ${HOME}/.vim/plugin.vim"

# neovim
alias nv="nvim"
alias n="nvim"

# For Tmux
alias trw="tmux rename-window"

# LOADS
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."

alias src="source ${HOME}/.bashrc"
# alias
alias eal="vim ${HOME}/.shell/alias.sh"
alias tmuxc="vim ${HOME}/.tmux.conf.local"

## For ls
[[ -e `which exa` ]] && alias ls="exa -sold"
[[ -e `which exa` ]] || alias ls="ls -htpF --color=auto"
alias l="ls"
[[ -e `which exa` ]] && alias ll="exa -lahsold"
[[ -e `which exa` ]] || alias ll="ls -alhpF"

## For clipboard xclip
alias pbcopy="xclip -selection clipboard"
alias pbpaste="xclip -selection clipboard -o"

## emacs
alias emacs="emacs -nw" ## 默认终端
alias ee="emacs"
alias ec='TERM=xterm-256color emacsclient -a "" -c -n'
alias ect='TERM=xterm-256color emacsclient -t'
alias ecq='emacsclient --eval "(kill-emacs)" && echo "quit emacs server"'

## For trash cli -- to rm
alias rm="trash-put"			## rm
alias thep="trash-empty"			## clear the trash
alias thre="trash-restore"		## restore some file
alias thls="trash-list"			## look the trash
alias thrm="trash-rm"			## delete trash file

## for vagrant
# alias vagrant="TERM=xterm-256color $(which vagrant)"

## For sudo
alias s="sudo"
alias ssu="sudo -i"

## For git
# commit
[[ -e `which commitizen` ]] && alias ag-commit-init="commitizen init cz-conventional-changelog --save --save-exact"
# base
alias ga="git add"              ## add changed file
alias gaa="git add *"           ## add changed files all
alias gcm="git commit -m"       ## git commit
alias gst="git status"          ## see the git repo status
alias gl="git log"              ## see the git logs
alias gph="git push"            ## git push
alias gpl="git pull"            ## pull the repo
alias gcl="git clone"           ## git clone something
# submodule
alias gsub="git submodule"      ## git submodule
alias gsadd="git submodule add"
alias gssy="git submodule sync"
# graph
alias ggraph="git log --graph --decorate --oneline --simplify-by-decoration --all"

gsrm() {
    echo "Removing submodule $1..."
    git submodule deinit $1
    git rm --cached $1
    git commit -am "Remove a submodule named $1"
    echo "Removed submodule $1"
}

# mirror for github.com
ggfast() {
    echo "Cloning $1 from https://hub.fastgit.org/..."
    git clone https://hub.fastgit.org/$1
    echo "Cloned $1."
}

alias ggcnpm='ggcnpm(){git clone https://github.com.cnpmjs.org/$1}; ggcnpm'
alias gsaddgf='gsaddgf(){git submodule add https://hub.fastgit.org/$1 $2}; gsaddgf'
alias gsaddgc='gsaddgc(){git submodule add https://github.com.cnpmjs.org/$1 $2}; gsaddgc'
alias gsaddgfc='gsaddgfc(){git submodule add https://hub.fastgit.org/$1 $2 && git commit -m "add $2"}; gsaddgfc'
alias gsaddgcc='gsaddgcc(){git submodule add https://github.com.cnpmjs.org/$1 $2 && git commit -m "add $2"}; gsaddgcc'

## For program
### CC
alias ccompile='cmake -H. -BDebug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=YES && ln -s Debug/compile_commands.json .'

# cpp-run filename
cpp-run() {
    echo "Compiling file..."
    tmpdir="/tmp/$(date '+%s')"
    mkdir -p ${tmpdir}
    g++ -o "${tmpdir}/$1" "$1.cpp"
    echo "Compiled! Enter input :D"
    ${tmpdir}/$1
    echo "done and clean"
    rm -rf ${tmpdir}
}
# cc-run filename
cc-run() {
    echo "Compiling file..."
    tmpdir="/tmp/$(date '+%s')"
    mkdir -p ${tmpdir}
    g++ -o "${tmpdir}/$1" "$1.cc"
    echo "Compiled! Enter input :D"
    ${tmpdir}/$1
    echo "done and clean"
    rm -rf ${tmpdir}
}

# c-run filename
c-run() {
    echo "Compiling file..."
    tmpdir="/tmp/$(date '+%s')"
    mkdir -p ${tmpdir}
    gcc -o "${tmpdir}/$1" "$1.c"
    echo "Compiled! Enter input :D"
    ${tmpdir}/$1
    echo "done and clean"
    rm -rf ${tmpdir}
}

## HOSTS
alias hosts='sudo wget https://raw.fastgit.org/googlehosts/hosts/master/hosts-files/hosts -O /etc/hosts'
